Skip to content

Validate the file table against the header size - #234

Merged
twogood merged 3 commits into
twogood:mainfrom
lemenkov:validate-file-table-bounds-2026-110716
Oct 18, 2026
Merged

twogood merged 3 commits into
twogood:mainfrom
lemenkov:validate-file-table-bounds-2026-110716

Conversation

@lemenkov

@lemenkov lemenkov commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

unshield_get_file_table() took the cabinet descriptor offset, the file table offset and the directory/file counts directly from the cabinet file and then read (directory_count + file_count) 32-bit words starting at data + cab_descriptor_offset + file_table_offset, without checking that this range stays within the header buffer. A cabinet with an out-of-range offset or an oversized file or directory count makes the loop read past the end of the allocated buffer.

Compute the start offset and the number of bytes the loop will read in 64-bit arithmetic so the additions cannot wrap, reject an empty table, and reject any table that would start past the buffer or extend beyond it before reading. The allocation result is now checked as well.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of empty or out-of-range file tables and allocation failures, preventing invalid archive data from being processed incorrectly.

unshield_get_file_table() took the cabinet descriptor offset, the file
table offset and the directory/file counts directly from the cabinet
file and then read (directory_count + file_count) 32-bit words starting
at data + cab_descriptor_offset + file_table_offset, without checking
that this range stays within the header buffer. A cabinet with an
out-of-range offset or an oversized file or directory count makes the
loop read past the end of the allocated buffer.

Compute the start offset and the number of bytes the loop will read in
64-bit arithmetic so the additions cannot wrap, reject an empty table,
and reject any table that would start past the buffer or extend beyond
it before reading. The allocation result is now checked as well.

Reported-by: haind-pwn (VulnCheck)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-18T15:30:20.041571Z e53b8a9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 887a4ee8-9040-4a6e-a30e-baf2469135a9
📥 Commits

Reviewing files that changed from the base of the PR and between 0d1e7cb and e53b8a9.

📒 Files selected for processing: 1
  • lib/libunshield.c

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

unshield_get_file_table now calculates table values with 64-bit arithmetic. It rejects empty or out-of-bounds tables and reports allocation failure by returning false.

Changes

File table validation

Layer / File(s) Summary
Validate and allocate the file table
lib/libunshield.c
The function uses 64-bit arithmetic for the table offset, entry count, and byte size. It checks for an empty table, an out-of-bounds range, and allocation failure.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: twogood

Merge Risk: ⚪ Minimal · up to e53b8

The file-table validation appears ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: validating the file table against the header size to prevent out-of-bounds reads.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the table’s bounds
And counts each entry with care
No empty list can slip on through
No oversized range gets there
If memory fails, it reports the news
Then hops away with carrots to spare

Comment @coderabbitai help to get the list of available commands.

unshield_get_file_table() took the cabinet descriptor offset, the file
table offset and the directory/file counts directly from the cabinet
file and then read (directory_count + file_count) 32-bit words starting
at data + cab_descriptor_offset + file_table_offset, without checking
that this range stays within the header buffer. A cabinet with an
out-of-range offset or an oversized file or directory count makes the
loop read past the end of the allocated buffer.

Compute the start offset and the number of bytes the loop will read in
64-bit arithmetic so the additions cannot wrap, reject an empty table,
and reject any table that would start past the buffer or extend beyond
it before reading. The allocation result is now checked as well.

Reported-by: haind-pwn (VulnCheck)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
@twogood
twogood force-pushed the validate-file-table-bounds-2026-110716 branch from e53b8a9 to e2ae618 Compare October 18, 2026 17:19
@twogood

twogood commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

What this change does: Validates the file-table range before reading archive-controlled offsets and counts. This is a meaningful improvement to the archive parser, with a small and focused diff.

I found no new correctness issue in the changed range check. The 64-bit arithmetic prevents the count/offset additions from wrapping, and the allocation failure is handled.

Should fix before merging: Add an automated regression test for a table extending past the header and for overflowing 32-bit counts. I ran a standalone probe covering a valid exact-fit table, an oversized table, an offset beyond the header, maximum counts, and an empty table; all behaved as this patch intends. The existing macOS test suite also passed (24/24).

Verdict: Worth merging; prioritize this contribution and include the bounds regression test. This protects the table itself; it does not validate every descriptor or string referenced by it.


Branch update correction: The initial update used a force-pushed rebase. The original PR commits have now been restored as first-parent history with a merge commit, pushed normally without force. Both the original and previously rebased commits remain reachable. The reviewed file contents are unchanged.

Review basis: main 313534b (after #199), with current logging, assertions, I/O callbacks, and GCC 14/15 CI preserved in conflict resolutions. No functional fixes to the findings above were folded into the branch update. Local checks used macOS arm64, shared Debug builds with bundled MD5 unless stated otherwise; native MSVC and glibc runtime checks were not performed.

@twogood twogood mentioned this pull request Oct 18, 2026
Restore the original contribution commits as the first-parent history.
Keep the reviewed conflict resolutions and current main without rewriting published history again.
@twogood
twogood merged commit d0d7d18 into twogood:main Oct 18, 2026
8 checks passed
@twogood

twogood commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants